/**
 * <pre>
 * @(#)DataSeries.java 1.00 2009-11-10
 * 
 * Copyright (c) 1998, 2009 Regular Individual. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Contributor(s):
 *     Haixu Huang
 * </pre>
 **/
package cn.sh.huang.chart.data;

import cn.sh.huang.chart.data.ext.Nomalizer;

/**
 * <pre>
 * DataSeries ...
 * 
 * @version 1.0
 * </pre>
 */
public class DataSeries implements Comparable
{
    private final String name;
    private final DataDecorator decorator;
    private final Nomalizer nomalizer;

    public DataSeries(String name, DataDecorator decorator, Nomalizer nomalizer)
    {
        this.name = name;
        this.decorator = decorator;
        this.nomalizer = nomalizer;
    }

    void setRange(Object o)
    {
        nomalizer.setRange(decorator.toValue(o));
    }

    public Double toNomalizedValue(Object o)
    {
        return nomalizer.normalize(decorator.toValue(o));
    }

    public String toText(Object o)
    {
        return decorator.toText(o);
    }

    public boolean equals(Object o)
    {
        return compareTo(o) == 0;
    }

    public int compareTo(Object o)
    {
        if (o instanceof DataSeries) {
            DataSeries d = (DataSeries) o;
            return name == null ? (d.name == null ? 0 : -1) : name.compareTo(d.name);
        }
        return -1;
    }
}
